
function quitaRow(row,tab,sel,val)
{
  
    var table = document.getElementById(tab); 
    var sel = document.getElementById(sel); 
    var val_ = document.createElement("option");
    val_.innerHTML = val ; 
    table.deleteRow(row); 
    sel.appendChild(val_);
}  

function pegaSelect(sel_,val)
{ 
    console.log(sel_);
    console.log(val);
    var val_ = document.createElement("option");
    val_.innerHTML = val ; 
    sel_.appendChild(val_);
}


function rmv(i,s,v)
{  
    $(i).parent().parent().remove();  
    pegaSelect(s,v); 
}

var c= "'";

function addNuevaRow(target)
{      
    var t_="";
    var val = getSelectedText(target);  
    if(target == "rolselect")
        t_= "tablarol"; 
    else if(target == "cmbRoles0")
        t_ = "tablarolPop";
    else if (target == "cmbPermisos0")
        t_ = "tablaprivPop"; 
    else if(target == "cmbRoles00")
        t_ = "tablamodrol";
    else if (target == "cmbPermisos00")
        t_ = "tablamodpriv";
    else if (target == "privroles")
        t_ = "tabla-agrega-rol";
    else if (target == "rolesroles")
        t_ = "tabla-agrega-rol-roles";
    else 
        t_= "tablapriv"; 
    if(val != null)
    {  
        //
        var table = document.getElementById(t_);  
        var t_size =  $('#'+t_+' tr').length;  
        if(t_== "tablapriv")
            t_size--;  
        var td2 = '<span>'+val+'</span>&nbsp<span class="glyphicon glyphicon-remove-sign" onclick="rmv(this,'+target+','+c+val+c+')"></span>';
        
        var r_ = "<tr><td>"+t_size+"</td><td>"+td2+"</td></tr>";
        $(r_).appendTo($("#"+t_));
       //
        var sel = document.getElementById(target); 
        sel.remove(sel.selectedIndex);
        return true;
    }
    return false;
}
 
 function getSelectedText(elementId) 
 {
    
    var elt = document.getElementById(elementId);
    if(elt != null)
    {
      
        if (elt.selectedIndex == -1 || elt.selectedIndex == 0)// AQUI ESTA EL ERROR
        {
        
            return null;//siempre retorna null
        }

        return elt.options[elt.selectedIndex].text;
    } 
    return null;
} 

function getDataTable(table)
{  
    
    var arr = new Array();
    var MyRows = $('#'+table).find('tbody').find('tr');
    for (var i = 0; i < MyRows.length; i++) 
    {
         arr.push($(MyRows[i]).find('td:eq(1)').find('span').html()); 
    }
    
    return arr;
}